---@diagnostic disable: lowercase-global, undefined-global, trailing-space

local _lang = SUGAR_webber_the_trainer:getModConfigDataFromTUNING('_lang')
local _hour,_min,_sec = STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.hour,STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.min,STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.sec
---将秒数转成时分秒
---@param t number
---@return string
---@nodiscard
local function format_duration(t)
    local hours = math.floor(t / 3600)
    t = t % 3600
    local minutes = math.floor(t / 60)
    local seconds = t % 60

    local time_str = ""
    if hours > 0 then
        time_str = time_str .. hours .. _hour
    end
    if minutes > 0 then
        time_str = time_str .. minutes .. _min
    end
    if seconds > 0 then
        time_str = time_str .. seconds .. _sec
    end
    if _lang == 'cn' and hours <= 0 and minutes > 0 and  seconds <= 0 then
        time_str = time_str .. '钟'
    end

    return time_str
end

---@type data_dish
local dishes = {} -- 键为料理名的料理定义表

-- -- 我只是一个例子,请把我注释掉
-- dishes.lan_m_chips = {
--     test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
--         return ((names.potato or 0) + (names.potato_cooked or 0)) == 3 and (names.butter or 0) == 1
--     end,
--     weight = 10, -- 食谱权重
--     priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
--     foodtype = FOODTYPE.VEGGIE, -- 食物类型
--     perishtime = 7, --腐烂时间/天
--     hunger = 20,
--     sanity = 1,
--     health = 1,
--     cooktime = 5, -- 烹饪时间/s
--     floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
--     potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
--     -- prefabs = {}, -- 该料理被注册为预制物之前需要先加载的预制物
--     -- tags = { "honeyed" }, -- 将被添加到预制物的tags
--     -- oneat_desc = "juice!", -- 烹饪指南中会显示的描述语
--     oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
--         -- eater:AddDebuff("buff_electricattack", "buff_electricattack")
--     end,
--     -- card_def = {ingredient = {{ "potato", 3 }, { "butter", 1 }}}, -- 将生成对应的食谱卡
--     -- imagename = "lan_m_chips", -- 贴图,不写则用prefab名
--     -- atlasname = "images/inventoryimages/lan_m_chips.xml", -- 图集,不写则用inventoryimages
--     -- cookbook_tex = "lan_m_chips_cookbook", -- 烹饪指南中显示的图片名,不写则用prefab名
--     -- cookbook_atlas = "images/inventoryimages/lan_m_chips_cookbook.xml", -- 烹饪指南中显示的图片图集,不写则用inventoryimages

--     lan = {
--         -- noedible = true,
--         -- nostackable = true,
--         -- nospiced = true,
--     },
    

--     -- isMasterfood = true, -- 是否大厨料理
--     -- maxstacksize = 40, -- 最大堆叠数量 不清楚的童鞋不要填这一项
--     -- onperishreplacement = nil, -- 腐烂产物，默认为腐烂物
--     -- perishfn = nil, -- 腐烂时的回调函数

-- }
-- 蛛丝爆浆蛋
dishes.webbert_dish_silkglandegg = {
    test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
        return (names.silk or 0) >= 1 and (names.spidergland or 0) >= 1 and (tags.sweetener or 0) >= 1 and (tags.egg or 0) >= 1
    end,
    weight = 10, -- 食谱权重
    priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
    foodtype = FOODTYPE.GOODIES, -- 食物类型
    perishtime = 7, --腐烂时间/天
    hunger = 20,
    sanity = 5,
    health = 5,
    cooktime = 20, -- 烹饪时间/s
    floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
    potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    -- prefabs = {}, -- 该料理被注册为预制物之前需要先加载的预制物
    -- tags = { "honeyed" }, -- 将被添加到预制物的tags
    oneat_desc = (function ()
        local _db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_dish_silkglandegg
        return subfmt(STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.webbert_dish_silkglandegg,{duration = format_duration(_db.buff_duration), val = (_db.buff_atkspeedadd*100)..'%'})
    end)(), -- 烹饪指南中会显示的描述语
    oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
        -- eater:AddDebuff("buff_electricattack", "buff_electricattack")
        eater:AddDebuff('buff_webbert_dish_silkglandegg_atkspeed_buff','buff_webbert_dish_silkglandegg_atkspeed_buff')
    end,
    -- card_def = {ingredient = {{ "potato", 3 }, { "butter", 1 }}}, -- 将生成对应的食谱卡
    -- imagename = "lan_m_chips", -- 贴图,不写则用prefab名
    -- atlasname = "images/inventoryimages/lan_m_chips.xml", -- 图集,不写则用inventoryimages
    cookbook_tex = "webbert_dish_silkglandegg", -- 烹饪指南中显示的图片名,不写则用prefab名
    cookbook_atlas = "images/cookbooks/webbert_dish_silkglandegg.xml", -- 烹饪指南中显示的图片图集,不写则用inventoryimages

    lan = {
        -- noedible = true,
        -- nostackable = true,
        -- nospiced = true,
        functional_medal_cook_certificate_consume = 2, -- 能力勋章: 烹饪勋章消耗耐久
    },


    -- isMasterfood = true, -- 是否大厨料理
    -- maxstacksize = 40, -- 最大堆叠数量 不清楚的童鞋不要填这一项
    -- onperishreplacement = nil, -- 腐烂产物，默认为腐烂物
    -- perishfn = nil, -- 腐烂时的回调函数

}
-- 月光蛛网冻
dishes.webbert_dish_mushroomsilkjelly = {
    test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
        return (names.silk or 0) >= 1 and (names.moon_cap or 0) >= 2  and (names.ice or 0) >= 1
    end,
    weight = 10, -- 食谱权重
    priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
    foodtype = FOODTYPE.GOODIES, -- 食物类型
    perishtime = 10, --腐烂时间/天
    hunger = 34,
    sanity = 10,
    health = 0,
    cooktime = 15, -- 烹饪时间/s
    floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
    potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    oneat_desc = (function ()
        local _db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_dish_mushroomsilkjelly
        return subfmt(STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.webbert_dish_mushroomsilkjelly,{duration = format_duration(_db.buff_duration), val = _db.buff_walkspeedmult})
    end)(),
    oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
        eater:AddDebuff('buff_webbert_dish_mushroomsilkjelly_buff','buff_webbert_dish_mushroomsilkjelly_buff')
    end,
    cookbook_tex = "webbert_dish_mushroomsilkjelly",
    cookbook_atlas = "images/cookbooks/webbert_dish_mushroomsilkjelly.xml",
    lan = {
        functional_medal_cook_certificate_consume = 5,
    },
    stacksize = 2,
}

-- 活力孢子羹
dishes.webbert_dish_sporeglandsoup = {
    test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
        return ((names.red_cap or 0) + (names.red_cap_cooked or 0)) >= 1 and ((names.green_cap or 0) + (names.green_cap_cooked or 0)) >= 1 and ((names.blue_cap or 0) + (names.blue_cap_cooked or 0)) >= 1 and (names.spidergland or 0) >= 1
    end,
    weight = 10, -- 食谱权重
    priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
    foodtype = FOODTYPE.GOODIES, -- 食物类型
    perishtime = 10, --腐烂时间/天
    hunger = 60,
    sanity = 5,
    health = 10,
    cooktime = 35, -- 烹饪时间/s
    floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
    potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    oneat_desc = (function ()
        local _db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_dish_sporeglandsoup
        return subfmt(STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.webbert_dish_sporeglandsoup,{duration = format_duration(_db.buff_duration), san = _db.buff_regensan, bp = (_db.buff_bloodpact_modifier * 100)..'%'})
    end)(),
    oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
        eater:AddDebuff('buff_webbert_dish_sporeglandsoup_buff','buff_webbert_dish_sporeglandsoup_buff')
    end,
    cookbook_tex = "webbert_dish_sporeglandsoup",
    cookbook_atlas = "images/cookbooks/webbert_dish_sporeglandsoup.xml",
    lan = {
        functional_medal_cook_certificate_consume = 3,
    },
}

-- 龙脊焚劫烩
dishes.webbert_dish_dragoninfernostew = {
    test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
        return ((names.dragonfruit or 0) + (names.dragonfruit_cooked or 0)) >= 1 and (names.nightmarefuel or 0) >= 1 and (names.firenettles or 0) >= 1 and (tags.veggie or 0) >= 1
    end,
    weight = 10, -- 食谱权重
    priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
    foodtype = FOODTYPE.GOODIES, -- 食物类型
    perishtime = 30, --腐烂时间/天
    hunger = 90,
    sanity = -10,
    health = -10,
    cooktime = 40, -- 烹饪时间/s
    floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
    potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    oneat_desc = (function ()
        local _db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_dish_dragoninfernostew
        return subfmt(STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.webbert_dish_dragoninfernostew,{duration = format_duration(_db.buff_duration)})
    end)(),
    oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
        eater:AddDebuff('buff_webbert_dish_dragoninfernostew_buff','buff_webbert_dish_dragoninfernostew_buff')
    end,
    cookbook_tex = "webbert_dish_dragoninfernostew",
    cookbook_atlas = "images/cookbooks/webbert_dish_dragoninfernostew.xml",
    lan = {
        noburnable = true,
        functional_medal_cook_certificate_consume = 10,
    },
}

-- 轮回之心
dishes.webbert_dish_respawnheart = {
    test = function(cooker, names, tags) -- 料理的测试函数，条件进行数值比较前必须判空
        return ((names.dragonfruit or 0) + (names.dragonfruit_cooked or 0)) >= 1 and (names.reviver or 0) >= 1 and (names.nightmarefuel or 0) >= 2
    end,
    weight = 10, -- 食谱权重
    priority = 99, -- @Runar: 料理优先级，严格的测试函数配合设定合理的料理优先级才能铸就好的料理。无端99还条件简单的无疑是给自己和其他模组添麻烦
    foodtype = FOODTYPE.GOODIES, -- 食物类型
    perishtime = 6, --腐烂时间/天
    hunger = 45,
    sanity = -5,
    health = 0,
    cooktime = 50, -- 烹饪时间/s
    floater = {'med', nil, 0.55}, -- 设置料理漂浮水面的数据
    potlevel = "low", -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    oneat_desc = STRINGS.MOD_WEBBER_THE_TRAINER.hovertext.webbert_dish_respawnheart,
    oneatenfn = function(inst, eater) -- 食用后执行的函数，在此实现buff
        eater:AddDebuff('buff_webbert_dish_respawnheart_buff','buff_webbert_dish_respawnheart_buff')
    end,
    cookbook_tex = "webbert_dish_respawnheart",
    cookbook_atlas = "images/cookbooks/webbert_dish_respawnheart.xml",
    lan = {
        functional_medal_cook_certificate_consume = 8,
    },
}

for k, v in pairs(dishes) do
    v.name = k -- 设置料理名
    v.basename = k -- 设置调味料理基础名
    v.weight = v.weight or 1 -- 设置料理权重
    v.priority = v.priority or 0 -- 设置料理优先级
    v.perishtime = (v.perishtime or 3)*TUNING.TOTAL_DAY_TIME
    v.cooktime = (v.cooktime or 15)/TUNING.BASE_COOK_TIME
    v.potlevel = v.potlevel or 'low' -- 贴图相对位置 
    v.overridebuild = v.overridebuild or k -- 设置料理锅上动画（贴图）所在的build压缩包（有时build名不一定为压缩包名）
    v.floater = v.floater or { "small", .05, .7 } -- 设置料理漂浮数据
    v.mod_webber_the_trainer = true -- 确定为模组料理便于本模组内进行调味处理，换个名也可
    v.cookbook_tex = (v.cookbook_tex or k) .. '.tex' -- 烹饪指南tex名，不设置则为prefab名
    v.cookbook_atlas = v.cookbook_atlas or ("images/inventoryimages/" .. k .. ".xml") -- 烹饪指南图集
    -- v.cookbook_catogory = "mod" -- 料理在烹饪指南中所处的目录。后续定义中被确认为模组料理，写了大概率不生效
    v.imagename = v.imagename or k -- 用于prefab中设置贴图名
    v.atlasname = v.atlasname or ("images/inventoryimages/" .. k .. ".xml") -- 用于指定库存贴图图集
    v.oneat_desc = v.oneat_desc or STRINGS.NAMES[string.upper(k)] or k -- 添加描述

    
    v.lan = v.lan or {}
    v.lan.noedible = v.lan.noedible or false
    v.lan.nostackable = v.lan.nostackable or false
    v.lan.noperishable = v.lan.noperishable or false
    v.lan.nospiced = v.lan.nospiced or false
end

return dishes